#ifndef SSQLQUERY_H
#define SSQLQUERY_H

#include <QObject>
#include <QtSql>

#define SQL_RESULT_OK "RESULT_OK"
#define SQL_RESULT_ERROR_UNIQUE "ERROR_UNIQUE"
#define SQL_RESULT_ERROR_FK "ERROR_FK"
#define SQL_RESULT_ERROR_RECORD_NOT_EXISTS "ERROR_RECORD_NOT_EXISTS"

struct SDbParams
{
    QString connectionName;
    QString dbName;
    QString dbUser;
    QString dbPass;
    QString dbHost;
    QString dbDriver;
};

class SSqlQuery : public QObject
{
    Q_OBJECT
private:
    QSqlError fLastError;
    SDbParams fDbParams;
    QSqlDatabase fDatabase;

    bool fConnected;
public:
    SSqlQuery(const SDbParams &dbParams, QObject *parent = 0);
    ~SSqlQuery();

    bool createConnection();
    void deleteConnection();

    QList <QSqlRecord> executeSql(const QString &queryText);

    SDbParams dbParams();

    QSqlError lastError();
    QList <QSqlRecord> sqlResult;
    QString simpleSqlResult;
    QString GetList(const QString &queryText);
    QString InsertSql(const QString &queryText);
    QString ExecSql(const QString &queryText);
signals:

public slots:

};

#endif // SSQLQUERY_H
